package com.yu.rabbitmq.one;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.yu.rabbitmq.utils.RabbitMqUnits;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Worker01 {

    private static String QUEUE_NAME = "hello";

    public static void main(String[] args) {
        try {
            Channel channel = RabbitMqUnits.getChannel();
            DeliverCallback callback = (consumerTag, delivery) -> {
                String message = new String(delivery.getBody());
                System.out.println("接受到的消息:"+message);
            };

            CancelCallback cancelCallback = (consumerTag)->{
                System.out.println("消息消息被中断");
            };
            System.out.println("C1等待接受消息");
            channel.basicConsume(QUEUE_NAME,true,callback,cancelCallback);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }


    }
}
